﻿@model IEnumerable<ZDSoft.UPMS.Model.BusinessPart.SituationType>
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>IndexS</title>
    <script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    <link href='@Url.Content("../../Scripts/PageCreater/Css/Style.css")' rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript">
        $(function () {
            $("#SituationType").change(function () {
                var list = $(this).val();
                var values = new Array();
                values = list.split(',');
                var name = values[1];
                window.location = "CreateRlueIndex?name=" + name;
            })
            var j = 0;
            var size = $("select").size();
            for (var i = 1; i < size; i++) {
                $("#select" + j).change(function () {
                    var cc = $(this).val();
                    if (cc == "实际情况") {
                        $(this).parent().next().find("div").eq(0).slideDown();
                        $(this).parent().next().find("div").eq(1).slideUp();
                    }
                    else {
                        $(this).parent().next().find("div").eq(0).hide();
                        $(this).parent().next().find("div").eq(1).slideDown();
                    }
                })
                j++;
            }
        })
        var i = 0;
        function delScroe(Modles) {
            var id = $(Modles).attr("id");
            $("tr").remove("#" + id);
        }
        function addScroe(obj) {
            i++;
            var xx = $(obj);
            xx.parent().parent().after("<tr id=" + i + "><td><input type='text' /></td> <td><input type='text'  /></td><td> <input type='text' /> </td> <td> <input id='" + i + "' style='border:0;width:50px;' value='-' type='button'   onclick='delScroe(this)' > </input></td></tr>");
        }

        var sum = "";
        function submit() {
            var value = $("#SituationType").val();
            var list = new Array();
            list = value.split(',');
            var up = $("#up").val();
            var down = $("#down").val();

            var stringvalue = "";
            var size = $("select").size();
            var entity = $("select");
            for (var j = 1; j < size; j++) {
                var cc = entity.eq(j).val();
                if (cc == "实际情况") {
                    var modle = entity.eq(j).parent().next().find("div").eq(0).find("input").val();
                    stringvalue += modle;
                }
                else {
                    var k = 0;
                    var entityone = entity.eq(j).parent().next().find("div").eq(1).find("input")
                    var modle = entity.eq(j).parent().next().find("div").eq(1).find("input").size();
                    for (var y = 0; y < modle - 1; y++) {
                        var vv = entityone.eq(y).val();
                        if (vv != "" && vv != "+" && vv != "-") {
                            k++;
                            if (k % 3 == 1) {
                                stringvalue += vv;
                            }
                            if (k % 3 == 2) {
                                stringvalue += "," + vv;
                            }
                            if (k % 3 == 0) {
                                stringvalue += "!" + vv + "-";
                            }
                        }
                    }
                    stringvalue = stringvalue.substring(0, stringvalue.length - 1);
                }
                stringvalue += "|";
            }
            stringvalue = stringvalue.substring(0, stringvalue.length - 1);

            $.post("/Rule/CreateFunction", { pid: list[0], up: up, down: down, str: stringvalue }, function () {
                alert("保存成功!")
                window.location("../Rule/SituationRuleList");
            });
        }
    </script>
    <style type="text/css">
        #mytable
        {
            width: 80%;
            padding: 0;
            margin: 0;
            border: 1px solid #C1DAD7;
        }
        th
        {
            height:30px;
            color: #007ea2;
            background-color: #B3E1F9;
        }
        td
        {
            text-align: center;
        }
        body, td, th
        {
            padding-left: 20px;
            font-family: 宋体, Arial;
            font-size: 12px;
        }
        #Save
        {
            background-image: url(../../Content/Images/but3.gif);
            width: 62px;
            height: 21px;
            border: 0px;
        }
        a
        {
            color: Blue;
            text-decoration: none;
        }
        input
        {
            width: 120px;
            border: 1px solid skyblue;
        }
    </style>
</head>
<body>
    <p>
        @Html.Raw(TempData["types"].ToString())
    </p>
    课时：<input id="up" type="text" style="width: 40px" />至：<input id="down" type="text"
        style="width: 40px" />
    <table id="mytable" style="margin-top: 15px;">
        <tr>
            <th>
                违纪情况
            </th>
            <th>
                操作
            </th>
            <th>
                规则设置
            </th>
        </tr>
        @{              
            var i = 0;
            var tmpup = "txtup";
            var tmpDown = "txtdown";
            var tmpRemove = "txtRemove";
            var tmpDeduction = "deduction";
            var tmpdiv = "tmpdiv";
            var tmpselect = "select";
            var tmpdivs = "divs";
        }
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @item.Name
                </td>
                <td>
                    <select id="@tmpselect@i">
                        <option value="阶段性">阶段性</option>
                        <option value="实际情况">实际情况</option>
                    </select>
                </td>
                <td>
                    <div id="@tmpdiv@i" style=" display:none;">
                        <table style="border: 0px;">
                            <tr>
                                <td>
                                    扣的分数
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <input id="@tmpDeduction@i" class="deduction"  type="text" />
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div id="@tmpdivs@i">
                        <table style="border: 0px;">
                            <tr>
                                <td>
                                    上限
                                </td>
                                <td>
                                    下限
                                </td>
                                <td>
                                    扣的分数
                                </td>
                            </tr>
                            <tr id="tr1">
                                <td>
                                    <input id="@tmpup@i" type="text" />
                                </td>
                                <td>
                                    <input id="@tmpDown@i" type="text" />
                                </td>
                                <td>
                                    <input id="@tmpRemove@i" type="text" />
                                </td>
                                <td>
                                    <input type="button" style="border: 0; width: 50px;" onclick="addScroe(this)" value="+" />
                                </td>
                            </tr>
                        </table>
                    </div>
                </td>
            </tr>  
                                                    i++;
        }
    </table>
    <br />
    <input type="button" onclick="submit()" value="保存" class="btn3" />
</body>
</html>
